package com.example.a2209_mianshi.flow_eventbus.utils

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken


object GSON {

    val gson: Gson by lazy {
        GsonBuilder().serializeNulls().disableHtmlEscaping().create()
    }

    fun toJson(source: Any?): String {
        return gson.toJson(source)
    }

    inline fun <reified T> fromJson(json: String): T? {
        return gson.fromJson(json, object : TypeToken<T>() {}.type)
    }

    fun <T> formJson(json: String, clazz: Class<T>): T {
        return gson.fromJson(json, clazz)
    }
}